package com.xingkeduo.business.order.controller;

import com.alibaba.fastjson.JSON;
import com.xingkeduo.business.order.domain.DataStatisticsService;
import com.xingkeduo.dto.param.DescriptionDto;
import com.xingkeduo.dto.param.StatisticeParam;
import com.xingkeduo.dto.response.*;
import com.xingkeduo.utils.ResponseUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;

import java.util.List;

import static com.xingkeduo.utils.Constant.API_URL_PREFIX;

/**
* @description: 数据统计Controller
* @author: ch
* @Param
* @return
* @date: 2019-07-16 15:12
**/
@RestController
@RequestMapping(API_URL_PREFIX + "/order/statistics")
@Slf4j
public class DataStatisticsController {


    @Resource
    private DataStatisticsService dataStatisticsService;

    /**
    * @description: 今日业绩
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 11:58
    **/
    @GetMapping("/performance")
    public ResponseEntity performanceQuery(@Valid StatisticeParam statisticeParam){
        PerformanceDto performanceDto = dataStatisticsService.performanceQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(performanceDto), HttpStatus.OK);
    }

    /**
    * @description: 今日业绩详情
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 11:59
    **/
    @GetMapping("/performance/info")
    public ResponseEntity performanceInfoQuery(@Valid StatisticeParam statisticeParam){
        PerformInfosDto performanceDto = dataStatisticsService.performanceInfoQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(performanceDto), HttpStatus.OK);
    }


    /**
    * @description: 服务质量
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 14:39
    **/
    @GetMapping("/service")
    public ResponseEntity service(@Valid StatisticeParam statisticeParam){
        ServiceInfoDto serviceInfoDto = dataStatisticsService.serviceQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(serviceInfoDto), HttpStatus.OK);
    }

    /**
    * @description: 服务质量详情
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 14:48
    **/
    @GetMapping("/service/info")
    public ResponseEntity serviceInfo(@Valid StatisticeParam statisticeParam){
        ServiceInfoDto serviceInfoDto = dataStatisticsService.serviceInfoQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(serviceInfoDto), HttpStatus.OK);
    }

    /**
    * @description: 服务订单来源
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 14:59
    **/
    @GetMapping("/source")
    public ResponseEntity source(@Valid StatisticeParam statisticeParam){
        OrderSourceInfoDto serviceInfoDto = dataStatisticsService.sourceQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(serviceInfoDto), HttpStatus.OK);
    }


    /**
    * @description: 服务订单来源详情
    * @author: ch
    * @Param [statisticeParam]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-17 14:59
    **/
    @GetMapping("/source/info")
    public ResponseEntity sourceInfo(@Valid StatisticeParam statisticeParam){
        OrderSourceInfoDto serviceInfoDto = dataStatisticsService.sourceInfoQuery(statisticeParam);
        return new ResponseEntity<>(ResponseUtils.getSuccess(serviceInfoDto), HttpStatus.OK);
    }




    /**
    * @description: 描述信息添加
    * @author: ch
    * @Param [descriptionDto]
    * @return org.springframework.http.ResponseEntity
    * @date: 2019-07-19 14:54
    **/
    @PostMapping("/description/add")
    public ResponseEntity descriptionAddInfo(@RequestBody List<DescriptionDto> descriptionDto){
        log.info("description{}", JSON.toJSONString(descriptionDto));
        dataStatisticsService.descriptionInfoQuery(descriptionDto);
        return new ResponseEntity<>(ResponseUtils.getSuccess(null), HttpStatus.OK);
    }


    @GetMapping("/description/get")
    public ResponseEntity descriptionInfo(){
        List<DescriptionDto> descriptionDto =  dataStatisticsService.descriptionInfo();
        return new ResponseEntity<>(ResponseUtils.getSuccess(descriptionDto), HttpStatus.OK);
    }
}



